/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bgIntlgn.client.entity.system;

import yuhuibear.poat.annotations.action.AutoGenerateValue;
import yuhuibear.poat.annotations.relation.Field;
import yuhuibear.poat.annotations.relation.Table;
import yuhuibear.poat.object.bean.Bean;

/**
 * 菜单实体
 * 
 * @author yuhuibear
 */
@Table(name = "menus", constrain = "")
public class Menu implements Bean, Comparable<Menu> {

	@AutoGenerateValue(skipOnNull = true, sqlToGet = "select currval('menus_id_seq')")
	@Field(name = "id", type = "bigserial", constrain = "primary key")
	private Long id;

	/**
	 * 父菜单ID
	 */
	@Field(name = "parent_id", type = "int8", constrain = "references menus(id) on update cascade on delete cascade")
	private Long parentId;

	/**
	 * 菜单名称
	 */
	@Field(name = "name", type = "varchar(40)", constrain = "")
	private String name;

	@Field(name = "tips", type = "varchar(100)", constrain = "")
	private String tips;

	public Menu() {
		this.name = "";
	}

	public Menu(String name) {
		this.name = name;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public String getTips() {
		return this.tips;
	}

	public void setTips(String tips) {
		this.tips = tips;
	}

	public String toString() {
		return name;
	}

	public int hashCode() {
		int h = 0;
		for (Character ch : name.toCharArray())
			h = h + (int) ch;
		return h;
	}

	public int compareTo(Menu o) {
		return (int) (id - o.getId());
	}
}
